<?php

namespace App\Providers;

use Blockchain\Blockchain;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Arr;

class BlockchainServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('blockchain', function ($app) {
            $config = $app->config->get('blockchain');
            $blockchain = new Blockchain(Arr::get($config, 'api_code'));
            $blockchain->setServiceUrl(Arr::get($config, 'service_url'));
            $blockchain->setTimeout(Arr::get($config, 'timeout_seconds'));
            $blockchain->Wallet->credentials(Arr::get($config, 'wallet.id'), Arr::get($config, 'wallet.main_password'), Arr::get($config, 'wallet.second_password') ?: null);
            return $blockchain;
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [
            'blockchain'
        ];
    }
}
